package com.headline.common;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created with Administrator
 * DATE:2016/11/9
 * Time:15:49
 */
public class DateHelper {


    /**
     * 字符串转10位时间戳
     *
     * @param time
     * @return
     */
    public static long dateToTimeSpan(String time) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date date = format.parse(time);
            return date.getTime() / 1000;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;

    }


    /**
     * 十位时间戳转时间字符串
     *
     * @param timeSpan
     * @return
     */
    public static String timeSpanToDate(Long timeSpan) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Long time = new Long(timeSpan * 1000);
        String d = format.format(time);
        try {
            Date date = format.parse(d);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return d;
    }
}
